package com.xym.manage.controller.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.xym.manage.pojo.Item;
import com.xym.manage.service.ItemService;

@Controller
@RequestMapping("api/item")
public class ApiItemController {

	@Autowired
	private ItemService itemService;
	
	/**
	 * 接口查询商品详情
	 * @param id
	 * @return
	 */
	@RequestMapping("{itemid}")
	public ResponseEntity<Item> queryItemById(@PathVariable("itemid")Long id){
		try {
			Item item = itemService.queryById(id);
			if(item!=null){
				return ResponseEntity.status(HttpStatus.OK).body(item);
			}
			return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
	}
}
